<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>活动管理</title>
    <#include "../../common/link.ftl">
    <link rel="stylesheet" type="text/css" href="/js/plugins/bootstrap-select/bootstrap-select.css"/>
    <script src="/js/plugins/bootstrap-select/bootstrap-select.js"></script>
    <link type="text/css" rel="stylesheet" href="/js/plugins/uploadifive/uploadifive.css" />
    <script type="text/javascript" src="/js/plugins/uploadifive/jquery.uploadifive.min.js"></script>
    <script src="/js/ckeditor/ckeditor.js"></script>

    <script>
        $(function () {
            // 日期插件
            jeDate({
                dateCell:"#applyStartTime",
                isinitVal:false,  //是否初始化时间
                isTime:true, //是否开启时间选择
                minDate:"2014-09-19 00:00:00"
            })
            jeDate({
                dateCell:"#applyEndTime",
                isinitVal:false,  //是否初始化时间
                isTime:true, //是否开启时间选择
                minDate:"2014-09-19 00:00:00"
            })
            jeDate({
                dateCell:"#startTime",
                isinitVal:false,  //是否初始化时间
                isTime:true, //是否开启时间选择
                minDate:"2014-09-19 00:00:00"
            })
            jeDate({
                dateCell:"#endTime",
                isinitVal:false,  //是否初始化时间
                isTime:true, //是否开启时间选择
                minDate:"2014-09-19 00:00:00"
            })

            //富文本框图片配置
            var ck = CKEDITOR.replace( 'details',{    // name = content 的textarea文本域   参数1：位置，参数2：上传的配置等
                filebrowserBrowseUrl: 'https://luowowo-12.oss-cn-shenzhen.aliyuncs.com',  // 预览路径，还没放到编辑器中     图片服务器，假装这里有
                filebrowserUploadUrl: '/uploadImg_ck.do' // 上传路径
            });

            // 图片上传
            $('.imgBtn').uploadifive({
                'auto' : true,    // 自动发送图片上传请求
                'uploadScript' : '/uploadImg.do',  // 图片上传的请求路径
                buttonClass:"btn-link",    // 点击按钮的class
                'fileObjName' : 'pic',   // 文件上传的参数名
                'buttonText' : '浏览...',
                'fileType' : 'image',  // 上传文件类型
                'multi' : false,    // 是否上传多个
                'fileSizeLimit'   : 5242880,  // 每次上传限制的文件大小
                'removeCompleted' : true, //取消上传完成提示
                'uploadLimit' : 1,  // 上传个数限制
                //'queueSizeLimit'  : 10,   // 文件上传区域大小的限制
                'overrideEvents': ['onDialogClose', 'onError'],    //onDialogClose 取消自带的错误提示
                'onUploadComplete' : function(file, data) {  // 回调函数
                    $("#coverUrl").attr("src" ,data);  // data 约定是json格式的格式地址
                    $("#imgUrl").val(data);

                },
                onFallback : function() {
                    $.messager.alert("温馨提示","该浏览器无法使用!");
                }
            });

            // 主办方
            $.get("/activity/listAssociation", {}, function (data) {
                var html = '';
                var associations = data.data;
                $.each(associations, function (index, item) {
                    html += '<option value="' + item.id + '">'+item.username+'</option>'
                })
                $("#sponsorId").html(html);

                $('#sponsorId').selectpicker('refresh'); //刷新组件
            })

            // 保存
            $("#btn_submit").click(function () {
                //异步提交时， 富文本框可能出问题
                $("#details").val(ck.getData());
                $("#editForm").ajaxSubmit(function (data) {
                    console.log(data);
                    if(data.code == 200){
                        window.location.href = "/activity/admin/list.do";
                    }else{
                        $.messager.alert("温馨提示", data.msg);
                    }
                })
            })
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="activityAdmin"/>
    <#include "../../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>活动新增/编辑</h1>
        </section>
        <section class="content">
            <div class="box">
                <form class="form-horizontal" action="/activity/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" value="${(activity.id)!}" name="id" >
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="title" class="col-sm-2 control-label">活动标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title" value="${(activity.title)!}" placeholder="请输入活动标题">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="coverUrl" class="col-sm-2 control-label">图片：</label>
                        <div class="col-sm-8">
                            <input type="hidden"  class="form-control" id="imgUrl"  name="imgUrl" value="${(activity.imgUrl)!}" >
                            <img src="${(activity.imgUrl)!'/images/default.jpg'}" width="100px" id="coverUrl">
                            <button type="button" class="imgBtn">浏览</button>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="sponsor" class="col-sm-2 control-label">主办方：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="sponsor" name="sponsor" value="${(activity.sponsor)!}" placeholder="请输入主办方">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="site" class="col-sm-2 control-label">活动地点：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="site" name="site" value="${(activity.site)!}" placeholder="请输入活动地点">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="person" class="col-sm-2 control-label">所需人数：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="person" name="person" value="${(activity.person)!}" placeholder="请输入所需人数">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="synopsis" class="col-sm-2 control-label">活动简介：</label>
                        <div class="col-sm-6">
                            <textarea  class="form-control" name="synopsis" >${(activity.synopsis)!}</textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="site" class="col-sm-2 control-label">报名时间：</label>
                        <div class="col-sm-6">
                            <div class="input-daterange input-group" id="jedate">
                                <input type="text" class="input-sm form-control wicon" name="applyStartTime" id="applyStartTime"
                                       value="${(activity.applyStartTime?string('yyyy-MM-dd HH:mm:ss'))!}" />
                                <span class="input-group-addon">--</span>
                                <input type="text" class="input-sm form-control wicon" name="applyEndTime" id="applyEndTime"
                                       value="${(activity.applyEndTime?string('yyyy-MM-dd HH:mm:ss'))!}" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="site" class="col-sm-2 control-label">活动时间：</label>
                        <div class="col-sm-6">
                            <div class="input-daterange input-group" id="jedate">
                                <input type="text" class="input-sm form-control wicon" name="startTime" id="startTime"
                                       value="${(activity.startTime?string('yyyy-MM-dd HH:mm:ss'))!}" />
                                <span class="input-group-addon">--</span>
                                <input type="text" class="input-sm form-control wicon" name="endTime" id="endTime"
                                       value="${(activity.endTime?string('yyyy-MM-dd HH:mm:ss'))!}" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="site" class="col-sm-2 control-label">负责人：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="dutyName" name="dutyName" value="${(activity.dutyName)!}" placeholder="请输入负责人姓名">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="site" class="col-sm-2 control-label">联系方式：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="mobile" name="mobile" value="${(activity.mobile)!}" placeholder="请输入负责人电话">
                        </div>
                    </div>

                    <#if !activity??>
                    <div class="form-group">
                        <label for="isAgree" class="col-sm-2 control-label">是否需要管理员审核：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="isAgree1" name="isAgree">
                                <option value="2">否</option>
                                <option value="1">是</option>
                            </select>
                            <script>
                                $("#isAgree1").val(${(activity.isAgree)!})
                            </script>
                        </div>
                    </div>
                    <#else>
                    <div class="form-group">
                        <label for="isAgree" class="col-sm-2 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="isAgree2" name="isAgree">
                                <option value="1">审核中</option>
                                <option value="2">发布成功</option>
                                <option value="3">发布失败</option>
                            </select>
                            <script>
                                $("#isAgree2").val(${(activity.isAgree)!})
                            </script>
                        </div>
                    </div>
                    </#if>

                    <div class="form-group">
                        <label for="details" class="col-sm-2 control-label">详细内容：</label>
                        <div class="col-sm-6">
                        <textarea id="details" name="details" class="ckeditor">${(activity.details)!}</textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-1 col-sm-6" style="margin-left: 35%">
                            <!--button如果是在form表单内部,不写type默认就是submit-->
                            <!-- 验证插件只支持submit按钮提交-->
                            <button id="btn_submit" type="button" class="btn btn-primary" style="margin-right: 20px; margin-bottom: 10px">保存</button>
                            <button type="reset" class="btn btn-danger" style="margin-right: 20px; margin-bottom: 10px">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </section>
    </div>
    <#include "../../common/footer.ftl">
</div>
</body>
</html>
